<template>
  <div class="br-layout-relative">
    <div class="br-layout-absolute" style="left:10px;right:10px;height: 40px;line-height: 40px;">
      <div class="br-layout-relative">
        <div class="br-left" style="width: 100px;">
          <div class="br-back" @click="quit"><i class="iconfont icon-fanhui"></i>&nbsp;&nbsp;<span>返回</span></div>
        </div>
        <div class="br-right" style="width: 350px;">
          <el-input placeholder="搜索" v-model="searchword" prefix-icon="el-icon-search" size="mini" clearable>
          </el-input>
        </div>
      </div>
    </div>
    <div class="br-layout-absolute" style="top: 40px;left: 10px;bottom: 0;right: 10px;">
      <div class="br-layout-relative">
        <div class="br-left" style="width: 190px;">
          <div class="list-view">
            <div class="item" :style="{'background-color':index===0?'#f2f7fe':'','color':index===0?'#3685f2':''}"
              @click="index=0">常用</div>
            <div class="item" :style="{'background-color':index===1?'#f2f7fe':'','color':index===1?'#3685f2':''}"
              @click="index=1">所有</div>
            <div class="item" :style="{'background-color':index===2?'#f2f7fe':'','color':index===2?'#3685f2':''}"
              @click="index=2">其他</div>
          </div>
        </div>
        <div class="br-right" style="left:190px;border-left: 1px solid lavender;">
          <div class="br-list-view">
            <div class="br-item-list">
              <div class="br-item br-boder" style="width: 110px;height: 120px;" v-if="index===0" v-for="(item,a) in commons"
                :key="a" @click="addDatabase(item)">
                <img :src="item.image" class="database-img" />
                <div class="database-text">{{item.name}}</div>
              </div>
              <div class="br-item br-boder" style="width: 120px;height: 120px;" v-if="index===1" v-for="(item,a) in all"
                :key="a" @click="addDatabase(item)">
                <img :src="item.image" class="database-img" />
                <div class="database-text">{{item.name}}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {
    accessData
  } from '@/api/database/database'
  export default {
    components: {},
    props: {},
    computed: {},
    data() {
      return {
        searchword: '',
        loading: false,
        index: 0,
        commons: [],
        all: [],
        others: [],
      }
    },
    methods: {
      quit() {
        this.$store.commit("CONNECTION_TEMPALTE", 0);
      },
      addDatabase(item) {
        this.$store.commit("CONNECTION_TEMPALTE", 2);
        this.$store.commit("CONNECTION_TYPE", item.id);
        this.$store.commit("CONNECTION_NAME", item.name);
      },
      accessData() {
        this.loading = true;
        accessData().then((res) => {
          this.loading = false;
          if (res.data.status == 200) {
            this.commons = res.data.data;
          }
        })
      }
    },
    created() {},
    mounted() {
      this.accessData();
    },
  }
</script>

<style lang="less" scoped>
  
  
  .br-list-view {
    position: relative;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
  }
  
  .br-list-view .br-item-list {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    display: flex;
    flex-flow: row wrap;
    align-content: flex-start
  }
  
  .br-list-view .br-item-list .br-item {
    position: relative;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    display: flex;
    margin: 10px 0 0 10px;
    justify-content: center;
    align-items: center;
    cursor: pointer;
  }
  
  .br-list-view .br-item-list .br-item:hover {
    box-shadow: 0 2px 8px 0 rgba(61, 77, 102, .15);
  }
  
  .list-view {
    width: 100%;
    height: 100%;
    position: relative;
    margin: auto;


    .item {
      width: 100%;
      height: 25px;
      position: relative;
      line-height: 25px;
      color: #3d4d66;
      font-size: 12px;
      cursor: pointer;

      &:hover {
        color: #3685f2;
        background-color: #f2f7fe;
      }


      .text {
        width: 190px;
        height: 100%;
        position: absolute;
        top: 0px;
        left: 25px;
        bottom: 0px;
        right: 0px;
      }
    }

  }

  .database-img {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    width: 110px;
    height: 90px;
  }

  .database-text {
    position: absolute;
    top: 90px;
    left: 0;
    bottom: 0;
    right: 0;
    color: #647185;
    background-color: #f2f4f7;
    text-align: center;
    line-height: 30px;
  }
</style>
